home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / Callbacks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-24  |  2.4 KB  |  76 lines  |  [TEXT/KAHL]

  1. /*                                    Callbacks.c                                    */
  2. /*
  3.  * Callbacks.c
  4.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * This is a group of six functions with a common form. They are called by AOCE to
  7.  * enumerate parts of the directory structure and, in turn, call back to functions
  8.  * in this module. They have exactly the same format, except for differences in
  9.  * the name of the variables and the type of the parameter. To emphasize the
  10.  * parallel structure -- and, not least, to save typing time -- I generate five of
  11.  * the six functions from a common macro definition. See the definition of
  12.  * MyForEachAttrTypeLookup at the end to see how the macro expands.
  13.  *
  14.  * This code was written by a professional programmer with  many years experience.
  15.  * Don't try this at home.
  16.  */
  17. #include "DTSSampleCSAM.h"
  18.  
  19. /*
  20.  *    Name    Function name            MyForEachEnumSpec
  21.  *    Parm    Function param type        DirEnumSpec
  22.  *    func    Callback function        enumerateParsePB.eachEnumSpec
  23.  */
  24. #define DIR        (*((DirParamBlockPtr) userPB))
  25. #define Callback(Name, Parm, func)                            \
  26.     pascal Boolean Name(                                    \
  27.             long                userPB,                        \
  28.             const Parm            *parmPtr                    \
  29.         )                                                    \
  30.     {                                                        \
  31.             Boolean                stopNow = FALSE;            \
  32.             long                saveA5;                        \
  33.             if (DIR.func != NULL) {                            \
  34.                 saveA5 = SetA5(DIR.header.saveA5);            \
  35.                 stopNow = (DIR.func)                        \
  36.                     (DIR.header.clientData, parmPtr);        \
  37.                 SetA5(saveA5);                                \
  38.             }                                                \
  39.             return (stopNow);                                \
  40.     }
  41.  
  42. Callback(MyForEachEnumSpec,
  43.             DirEnumSpec,    enumerateParsePB.eachEnumSpec)
  44. Callback(MyForEachRecordID,
  45.             RecordID,         enumeratePseudonymParsePB.eachRecordID)
  46. Callback(MyForEachLookupRecordID,
  47.             RecordID,        lookupParsePB.eachRecordID)
  48. Callback(MyForEachAttrType,
  49.             AttributeType,    enumerateAttributeTypesParsePB.eachAttrType)
  50. Callback(MyForEachAttrValue,
  51.             Attribute,        lookupParsePB.eachAttrValue)
  52.  
  53. /*
  54.  * Always one guy what gotta be clever. MyForEachAttrTypeLookup
  55.  * is just like the other callbacks except for the extra
  56.  * parameter.
  57.  */
  58. pascal Boolean
  59. MyForEachAttrTypeLookup(
  60.         long                    userPB,
  61.         const AttributeType        *parmPtr,
  62.         AccessMask                myAttrAccMask
  63.     )
  64. {
  65.         Boolean                stopNow = FALSE;
  66.         long                saveA5;
  67.         
  68.         if (DIR.lookupParsePB.eachAttrType != NULL) {
  69.             saveA5 = SetA5(DIR.header.saveA5);
  70.             stopNow = (DIR.lookupParsePB.eachAttrType)
  71.                 (DIR.header.clientData, parmPtr, myAttrAccMask);
  72.             SetA5(saveA5);
  73.         }
  74.         return (stopNow);
  75. }
  76.